-
Notifications
You must be signed in to change notification settings - Fork 51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CDConfig: Add cd_content for file templating #61
Conversation
// Key/Values to add to the CD. The keys represent the paths, and the values | ||
// contents. It can be used alongside `cd_files`, which is useful to add large | ||
// files without loading them into memory. If any paths are specified by both, | ||
// the contents in `cd_content` will take precedence. | ||
// | ||
// Usage example (HCL): | ||
// | ||
// ```hcl | ||
// cd_files = ["vendor-data"] | ||
// cd_content = { | ||
// "meta-data" = jsonencode(local.instance_data) | ||
// "user-data" = templatefile("user-data", { packages = ["nginx"] }) | ||
// } | ||
// cd_label = "cidata" | ||
// ``` | ||
CDContent map[string]string `mapstructure:"cd_content"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Love this 👍🏼
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This LGTM, super nice, thanks, waiting for #62 to be fixed/merged first before running manual tests.
Hi there @saleemrashi, #62 got merged, do you have the time to rebase & test this ? Thanks ! |
@azr Rebased and added tests 🙏 (and caught the missing |
(Sorry, pressed the button by accident 😄) |
up AddContent
|
||
func (s *StepCreateCD) AddContent(dst, path, content string) error { | ||
// Join Cleans the path so we can join it without path traversal issues. | ||
dstPath := filepath.Join(dst, path) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed the filepath.Clean
call as Join
already does that ! :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@azr From testing, doing filepath.Join("/folder", "../hello")
would result in /hello
which I don't think would be intended behaviour. Doing filepath.Clean
on an absolute path would turn ../hello
into /hello
so it joins to /folder/hello
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested this a little; this looks great to me ! Thanks !
Implement
cd_content
from hashicorp/packer#10859, allowing file templating similar tohttp_content
.There currently aren't any tests for this feature. I'd like to first make the
cd_files
tests more robust (at the moment they only test that there are the expected number of keys infilesAdded
), and then add tests forcd_content
(including when used alongsidecd_files
).